<? require_once("sitemap.php"); ?>
<?
$action="start";

if (!empty($_POST['action']))
{
	$action = $_POST['action'];
}
if (!empty($_POST['searchitemname']))
{
	$searchitemname = $_POST['searchitemname'];
}
if (!empty($_POST['searchplayername']))
{
	$searchplayername = $_POST['searchplayername'];
}
?>
<html>
	<title><? echo (":" . $HTTP_SERVER_VARS['REMOTE_user'] . ": ". $Botname); ?>'s EL-BOT trade Log</title>
<body>
	<h1><? echo ($Botname); ?>'s EL-BOT trade Log</h1>
	<? include "maxlisting.php" ?>
<?
$sql = "SELECT tradelog.id, tradelog.knownitemsid, knownitems.name, tradelog.quantity, tradelog.price, tradelog.username, tradelog.tradetime, tradelog.action FROM tradelog,knownitems WHERE tradelog.knownitemsid=knownitems.id AND tradelog.botid=$botid ";
if($searchitemname != "")
	$sql .= "AND knownitems.name LIKE '%$searchitemname%' ";
if($searchplayername != "")
	$sql .= "AND tradelog.username LIKE '%$searchplayername%' ";
$sql .= "ORDER BY tradelog.id DESC LIMIT $max";
$result = mysql_query($sql,$db);
echo "2" . mysql_error();
$buy = 0;
$sale = 0;
echo mysql_num_rows($result) . " actions returned";

	$o = '<table border="1" cellpadding="0" cellspacing="0">
		<tr>
			<td align="center">id</td>
			<td align="center">name<br>
<form method="post" action = "' . $_SERVER['PHP_SELF'] . '" onSubmit="return false;"><input type="text" name = "searchitemname" value="'.$searchitemname.'" onchange="this.form.submit();">
</td>
			<td align="center">quantity</td>
			<td align="center">price</td>
			<td align="center">Total</td>
			<td align="center">username<br>
<input type="text" name = "searchplayername" value="'.$searchplayername.'" onchange="this.form.submit();"></form>
</td>
			<td align="center">Date</td>
			<td align="center">action</td>			
		</tr>';
			$buy = 0;
			$sell = 0;
			while ($myrow = mysql_fetch_row($result))
			{
			$o .= '<tr bgcolor="';
			if($myrow[7]=="donate" || ($myrow[7]=="buy" && $myrow[4]=='0'))
				$o .="lightgreen";
			else if($myrow[7]=="buy")
				$o .= "#FF4444";
			else if($myrow[7]=="sale")
				$o .= "lightblue";
			else
				$o .="white";
			$o .= '">
					<td align="right">'.$myrow[0].'</td>
					<td>'.$myrow[2].'</td>
					<td align="right">'.$myrow[3].'</td>
					<td align="right">'.$myrow[4].'</td>
					<td align="right">';
					$total=($myrow[3])*($myrow[4]);
					if(strpos($total,'.'))
					{
						$total=(int)$total;
						if(strpos($total,'-'))
							$total--;
						else
							$total++;
					}
					$o .= $total.'</td>
					<td>'.$myrow[5].'</td>
					<td>'.$myrow[6].'</td>
					<td>'.$myrow[7].'</td>';
					if($myrow[7] == "buy")
					{
						$buy += $total;
					}
					if($myrow[7] == "sale")
					{
						$sale += $total;
					}
				$o .= '</tr>';
			}
$o .='</table>';
		if($buy>$sale)
			$ev = "loss";
		else
			$ev = "profit";
		echo "&nbsp;&nbsp;&nbsp;Buy $buy&nbsp;&nbsp;sale $sale&nbsp;&nbsp;Difference " . ($sale - $buy) . " $ev";
		print $o;
		echo "</body>
</html>
";
